//
//  DHBaseTVController.swift
//  Weibo
//
//  Created by Holfioo on 15/8/31.
//  Copyright © 2015年 Holfioo. All rights reserved.
//

import UIKit

// 在class 上直接遵守代理协议
class DHBaseTVController: UITableViewController {

    // 判断登录状态
//    var login = DHUserAccount.loadUserAccount()?.access_token != nil
//    var login = false
    var login = DHUserAccountViewModel.sharedUserAccount.userLogin // 登录状态的一个按钮
    // base的一个全局共享的属性
    var visitorView: DHVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 三位运算判断登录状态
        login ? super.viewDidLoad() : navBarSetup()
        // 设置代理，遵守代理方法
//        visitorView?.delegate = self
    }
    
    private func navBarSetup() {
        // 设置相关属性。调用view
        visitorView = DHVisitorView()
        view = visitorView
//        view.backgroundColor = UIColor.orangeColor()
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillRegister")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillLogin")
        visitorView?.loginBtn.addTarget(self, action: "visitorViewWillLogin", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.registerBtn.addTarget(self, action: "visitorViewWillRegister", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    // 保证方法的安全。
    @objc private func visitorViewWillLogin() {
//        print("登录")
        let vc = OAuth()
        presentViewController(UINavigationController(rootViewController: vc), animated: true, completion: nil)
    }
    @objc private func visitorViewWillRegister() {
        //
        printLog("注册")
    }
}
